<template>
	<view>
		<uni-row class="demo-uni-row">
			<uni-col>
				<uni-search-bar placeholder="请输入车牌查询" @confirm="search" v-model="queryParams.carNo"
					@input="search">
				</uni-search-bar>
			</uni-col>
		</uni-row>
		<scroll-view style="height: calc(100vh - 90rpx - 110rpx);"  refresher-enabled  :refresher-triggered='isPull'
			@refresherrefresh='refresh' scroll-y="true"  @scrolltolower="lower">
			<uni-list>
				<template v-for="item in tableList">
					<uni-list-item :title="item.carNo" :note="item.preBookDate"
						:rightText="item.deptName" badge-text="12"></uni-list-item>
				</template>
				<view style="border-top: 1px solid #f1f1f1;">
					<uni-load-more :status="status" />
				</view>
			</uni-list>
		</scroll-view>
	</view>
</template>

<script>
	import {
		listLog
	} from "@/api/control/log.js";
	export default {
		name: 'control_log',
		data() {
			return {
				loading: false,
				isPull: false,
				queryParams: {
					carNo: undefined,
					pageSize: 20,
					pageNum: 1,
				},
				total: 0,
				tableList: []
			}
		},
		onShow() {
			this.search()
		},
		computed: {
			role() {
				let r = this.$store.getters.roles || []
				return r.find(f => f == 'admin')
			},
			status() {
				let txt = 'more'
				if (this.loading) return 'loading'
				if (this.total <= this.tableList.length ) return 'no-more'
				return txt
			}
		},
		methods: {
			lower() {
				if (this.total <= this.tableList.length ) return
				this.queryParams.pageNum++
				this.getList()
			},
			search(){
				this.queryParams.pageNum = 1
				this.total = 0
				this.tableList = []
				this.getList()
			},
			refresh() {
				this.isPull = true
				this.search()
			},
			getList() {
				this.loading = true;
				listLog(this.queryParams).then(response => {
					this.tableList = [...this.tableList, ...response.rows];
					this.total = response.total;
					this.loading = false;
					this.isPull = false;
				})
			},
		}
	}
</script>

<style scoped>
.demo-uni-row{
	background-color: #3c96f3;
}
.my-button{
	height: 68rpx;
	line-height: 68rpx;
	text-align: center;
}
</style>
